<template>
  <view :class="isScroll ? '' : 'no-srcoll'" ref="mainview">

    <view class="head_top">
      <view class="header_box">
        <uni-row>
          <uni-col :span="1">
            <view class="head_icon tc">
              <qui-icon class="head_back" name="icon-back1" size="38" @tap="gotoPage('/mainpage/bbs/categories')">
              </qui-icon>
            </view>
          </uni-col>
          <uni-col :span="17">
            <mainheader @search="InputSearch"></mainheader>
          </uni-col>
          <uni-col :span="3">
            <view class="head_icon tc">
              <qui-icon name="icon-add" size="38" @tap="OpenPublish"></qui-icon>
              发帖
            </view>
          </uni-col>
          <uni-col :span="3">
            <view :class="['head_icon tc ', redCircle ? 'message' : '']">

              <qui-icon name="icon-message" size="38" @tap="gotoPage('/pages/home/index?cur_index=2')"></qui-icon>
              消息
            </view>

          </uni-col>
        </uni-row>
      </view>
    </view>


    <diy :diy-items="items"></diy>
    <qui-category :searchIds="searchIds" @admin="admin"></qui-category>
    <qui-content-up class="ivideo" v-for="(item, index1) in threads_top" :item="item" :key="index1"
      :currentindex="index1" :pay-status="(item.thread.price > 0 && item.thread.paid) || item.thread.price == 0"
      :user-name="item && item.user && item.user.userName" :is-real="item && item.user && item.user.isRealName"
      :themeLike="item.thread.likedCount" :themeComment="item.thread.postCount" :themeView="item.thread.viewCount"
      :theme-image="item && item.user && item.user.avatar" :answer-image="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.avatarUrl
      " :them-pay-btn="item.thread.price > 0 || item.thread.attachmentPrice > 0" :user-groups="[item.group]"
      :user-answer-groups="
        handleGroup(
          item.thread.extension &&
            item.thread.extension.question &&
            item.thread.extension.question.group,
        )
      " :theme-time="item.thread.createdAt" :theme-time-answer="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.answeredAt
      " :theme-content="item.thread.type == 1 ? item.thread.title : item.thread.summary"
      :thread-type="item.thread.type" :media-url="
        item.thread.extension &&
          item.thread.extension.video &&
          item.thread.extension.video.mediaUrl
      " :is-great="item.thread && item.thread.isLiked" :theme-like="item.thread && item.thread.likedCount"
      :theme-comment="item.thread.postCount" :images-list="item.attachment" :post-goods="
        item.thread.extension && item.thread.extension.goods ? item.thread.extension.goods : ''
      " :theme-essence="item.thread.isEssence" :video-width="
        item.thread.extension && item.thread.extension.video && item.thread.extension.video.width
      " :video-height="
        item.thread.extension && item.thread.extension.video && item.thread.extension.video.height
      " :video-id="
        item.thread.extension && item.thread.extension.video && item.thread.extension.video.id
      " :cover-image="
        item.thread.extension &&
          item.thread.extension.video &&
          item.thread.extension.video.coverUrl
      " :duration="
        item.thread.extension &&
          item.thread.extension.video &&
          item.thread.extension.video.duration
      " :is-deleted="item.isDeleted" :questions-name="item && item.user && item.user.userName" :be-ask-name="
        item.thread.extension && item.thread.extension.question
          ? item.thread.extension.question.beUserName
          : ''
      " :question-content="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.content
      " :add-ask="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.isAnswer
      " :onlooker-number="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.onlookerNumber
      " :free-ask="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.price == 0
      " :ask-price="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.price
      " :ask-content="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.content
      " :onlooker-unit-price="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.onlookerUnitPrice
      " :on-looker="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.onlookerUnitPrice == 0
      " :thread-position="
        item.thread.location
          ? [
              item.thread.location,
              item.thread.address,
              item.thread.longitude,
              item.thread.latitude,
            ]
          : []
      " :thread-audio="
        item.thread.threadAudio ||
          (item.thread && item.thread.extension && item.thread.extension.video)
      " :is-new-interface="!!(item.thread && item.thread.extension && item.thread.extension.video)" @handleIsGreat="
        handleIsGreat(
          item.thread.firstPostId,
          item.thread.canLike,
          item.thread.isLiked,
          item.thread.likedCount,
          item.thread,
        )
      " @commentClick="commentClick(item.thread.pid)" @contentClick="contentClick(item)"
      @answeClick="answeClick(item.user.pid)" @beAskClick="beAskClick(item.thread.extension.question.userId)"
      @backgroundClick="contentClick(item)" @headClick="headClick(item.user.pid)"
      @headAnswerClick="headAnswerClick(item.thread.extension.question.beUserId)" @videoPlay="handleVideoPlay"
      @scrollheight="scrpllsip"></qui-content-up>
    <uni-segmented-control :current="current" :values="tabs" styleType="button" activeColor="#4bced7"
      @clickItem="TabClick"></uni-segmented-control>


    <qui-content v-if="current!=3" class="ivideo" v-for="(item, index) in threads" :item="item" :ref="'myVideo' + index"
      :key="index" :currentindex="index"
      :pay-status="(item.thread.price > 0 && item.thread.paid) || item.thread.price == 0"
      :user-name="item && item.user && item.user.userName" :is-real="item && item.user && item.user.isRealName"
      :themeLike="item.thread.likedCount" :themeComment="item.thread.postCount" :themeView="item.thread.viewCount"
      :theme-image="item && item.user && item.user.avatar" :answer-image="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.avatarUrl
      " :them-pay-btn="item.thread.price > 0 || item.thread.attachmentPrice > 0" :user-groups="[item.group]"
      :user-answer-groups="
        handleGroup(
          item.thread.extension &&
            item.thread.extension.question &&
            item.thread.extension.question.group,
        )
      " :theme-time="item.thread.createdAt" :theme-time-answer="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.answeredAt
      " :theme-content="item.thread.type == 1 ? item.thread.title : item.thread.summary"
      :thread-type="item.thread.type" :media-url="
        item.thread.extension &&
          item.thread.extension.video &&
          item.thread.extension.video.mediaUrl
      " :is-great="item.thread && item.thread.isLiked" :theme-like="item.thread && item.thread.likedCount"
      :theme-comment="item.thread.postCount" :images-list="item.attachment" :post-goods="
        item.thread.extension && item.thread.extension.goods ? item.thread.extension.goods : ''
      " :theme-essence="item.thread.isEssence" :video-width="
        item.thread.extension && item.thread.extension.video && item.thread.extension.video.width
      " :video-height="
        item.thread.extension && item.thread.extension.video && item.thread.extension.video.height
      " :video-id="
        item.thread.extension && item.thread.extension.video && item.thread.extension.video.id
      " :cover-image="
        item.thread.extension &&
          item.thread.extension.video &&
          item.thread.extension.video.coverUrl
      " :duration="
        item.thread.extension &&
          item.thread.extension.video &&
          item.thread.extension.video.duration
      " :is-deleted="item.isDeleted" :questions-name="item && item.user && item.user.userName" :be-ask-name="
        item.thread.extension && item.thread.extension.question
          ? item.thread.extension.question.beUserName
          : ''
      " :question-content="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.content
      " :add-ask="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.isAnswer
      " :onlooker-number="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.onlookerNumber
      " :free-ask="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.price == 0
      " :ask-price="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.price
      " :ask-content="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.content
      " :onlooker-unit-price="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.onlookerUnitPrice
      " :on-looker="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.onlookerUnitPrice == 0
      " :thread-position="
        item.thread.location
          ? [
              item.thread.location,
              item.thread.address,
              item.thread.longitude,
              item.thread.latitude,
            ]
          : []
      " :thread-audio="
        item.thread.threadAudio ||
          (item.thread && item.thread.extension && item.thread.extension.video)
      " :is-new-interface="!!(item.thread && item.thread.extension && item.thread.extension.video)" @handleIsGreat="
        handleIsGreat(
          item.thread.firstPostId,
          item.thread.canLike,
          item.thread.isLiked,
          item.thread.likedCount,
          item.thread,
        )
      " @commentClick="commentClick(item.thread.pid)" @contentClick="contentClick(item)"
      @answeClick="answeClick(item.user.pid)" @beAskClick="beAskClick(item.thread.extension.question.userId)"
      @backgroundClick="contentClick(item)" @headClick="headClick(item.user.pid)"
      @headAnswerClick="headAnswerClick(item.thread.extension.question.beUserId)" @videoPlay="handleVideoPlay"
      @scrollheight="scrpllsip"></qui-content>

    <view class="content">
      <qui-content-video v-if="current==3" class="ivideo" v-for="(item, index) in threads" :item="item"
        :ref="'myVideo' + index" :key="index" :currentindex="index"
        :pay-status="(item.thread.price > 0 && item.thread.paid) || item.thread.price == 0"
        :user-name="item && item.user && item.user.userName" :is-real="item && item.user && item.user.isRealName"
        :themeLike="item.thread.likedCount" :themeComment="item.thread.postCount" :themeView="item.thread.viewCount"
        :theme-image="item && item.user && item.user.avatar" :answer-image="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.avatarUrl
      " :them-pay-btn="item.thread.price > 0 || item.thread.attachmentPrice > 0" :user-groups="[item.group]"
        :user-answer-groups="
        handleGroup(
          item.thread.extension &&
            item.thread.extension.question &&
            item.thread.extension.question.group,
        )
      " :theme-time="item.thread.createdAt" :theme-time-answer="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.answeredAt
      " :theme-content="item.thread.type == 1 ? item.thread.title : item.thread.summary"
        :thread-type="item.thread.type" :media-url="
        item.thread.extension &&
          item.thread.extension.video &&
          item.thread.extension.video.mediaUrl
      " :is-great="item.thread && item.thread.isLiked" :theme-like="item.thread && item.thread.likedCount"
        :theme-comment="item.thread.postCount" :images-list="item.attachment" :post-goods="
        item.thread.extension && item.thread.extension.goods ? item.thread.extension.goods : ''
      " :theme-essence="item.thread.isEssence" :video-width="
        item.thread.extension && item.thread.extension.video && item.thread.extension.video.width
      " :video-height="
        item.thread.extension && item.thread.extension.video && item.thread.extension.video.height
      " :video-id="
        item.thread.extension && item.thread.extension.video && item.thread.extension.video.id
      " :cover-image="
        item.thread.extension &&
          item.thread.extension.video &&
          item.thread.extension.video.coverUrl
      " :duration="
        item.thread.extension &&
          item.thread.extension.video &&
          item.thread.extension.video.duration
      " :is-deleted="item.isDeleted" :questions-name="item && item.user && item.user.userName" :be-ask-name="
        item.thread.extension && item.thread.extension.question
          ? item.thread.extension.question.beUserName
          : ''
      " :question-content="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.content
      " :add-ask="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.isAnswer
      " :onlooker-number="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.onlookerNumber
      " :free-ask="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.price == 0
      " :ask-price="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.price
      " :ask-content="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.content
      " :onlooker-unit-price="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.onlookerUnitPrice
      " :on-looker="
        item.thread.extension &&
          item.thread.extension.question &&
          item.thread.extension.question.onlookerUnitPrice == 0
      " :thread-position="
        item.thread.location
          ? [
              item.thread.location,
              item.thread.address,
              item.thread.longitude,
              item.thread.latitude,
            ]
          : []
      " :thread-audio="
        item.thread.threadAudio ||
          (item.thread && item.thread.extension && item.thread.extension.video)
      " :is-new-interface="!!(item.thread && item.thread.extension && item.thread.extension.video)" @handleIsGreat="
        handleIsGreat(
          item.thread.firstPostId,
          item.thread.canLike,
          item.thread.isLiked,
          item.thread.likedCount,
          item.thread,
        )
      " @commentClick="commentClick(item.thread.pid)" @contentClick="contentClick(item)"
        @answeClick="answeClick(item.user.pid)" @beAskClick="beAskClick(item.thread.extension.question.userId)"
        @backgroundClick="contentClick(item)" @headClick="headClick(item.user.pid)"
        @headAnswerClick="headAnswerClick(item.thread.extension.question.beUserId)" @videoPlay="handleVideoPlay"
        @scrollheight="scrpllsip"></qui-content-video>
    </view>
  
  </view>
</template>

<script>
  import {
    throttle,
    get
  } from 'lodash';
  import apiRequest from '../../api/new-api';
  import QuiCategory from '@/components/qui-category/qui-category.vue'
  import QuiContentUp from './qui-content-up/qui-content-up.vue'
  import QuiContentVideo from './qui-content-video/qui-content-video.vue'
  import mainheader from '../header/categories_header.vue';
  import diy from '@/components/diy/diy.vue';
  import user from '@/mixin/user';
  export default {
    components: {
      QuiCategory,
      HomeFooter,
      QuiContentUp,
      mainheader,
      diy,
      QuiContentVideo
    },
    mixins: [user],
    data() {

      return {
        items: [],
        loadingType: 'more', // 上拉加载状态
        current: 0,
        tabs: ['最新', '精华', '附近', '视频'],
        isScroll: true,
        searchIds: 0,
        types: '',
        threads: [],
        threads_top: [],
        pageNum: 1,
        threadEssence: 0, // 筛选精华 '' 不筛选 yes 精华 no 非精华
        threadFollow: 0, // 关注的主题 传当前用户 ID
        preThreadsData: [],
        toplogo: '',
        bgcolor: '',
        keyword: '',
        scrollTop: 0,
        location: {
          longitude: 0,
          latitude: 0
        }
      }
    },
    mounted() {

    },
    onLoad(e) {
      this.searchIds = parseInt(e.search_ids);
      this.current = e.current;

      this.TabClick({
        currentIndex: e.current
      })
      // this.loadThreads()
      this.LoadTopThreads();
    },
    onPullDownRefresh() {
      this.pageNum = 1;
      this.threads = [];
      this.threads_top = [];
      this.loadThreads()
      this.LoadTopThreads();
      setTimeout(function() {
        uni.stopPullDownRefresh();
      }, 1000);
    },
    // 上拉加载
    onReachBottom() {
      if (this.loadingType !== 'more') {
        return;
      }
      this.pageNum += 1;
      this.isResetList = false;
      this.loadThreads();
    },
    created() {

      this.preThreadsData = null;
      this.getData(10025);
      // 详情页删除帖子和新增帖子
      this.$u.event.$on('refreshHome', () => {
        this.isResetList = true;
        this.pageNum = 1;
        this.preThreadsData = null; // 重置预取数据
        this.LoadTopThreads();
        this.loadThreads();
      });
      // 详情页删除帖子后在首页删除
      this.$u.event.$on('deleteThread', () => {
        this.threads = [];
        this.isResetList = true;
        this.pageNum = 1;
        this.preThreadsData = null; // 重置预取数据
        this.LoadTopThreads();
        this.loadThreads();
      });
      // 编辑删除图片后首页删除图片
      this.$u.event.$on('deletedImg', res => {
        this.threads.forEach(item => {
          if (item.thread.pid === res.threadId) {
            item.attachment.splice(res.index, 1);
          }
        });
      });
      // 置顶列表添加数据当详情页置顶时
      this.$u.event.$on('stickyThread', data => {
        this.LoadTopThreads();
        this.threads.forEach((item, index) => {
          if (item.thread.pid === data._jv.id) {
            this.threads.splice(index, 1);
          }
        });
      });
      // 详情页编辑增加图片时首页增加图片
      this.$u.event.$on('refreshImg', res => {
        // eslint-disable-next-line no-restricted-syntax
        for (const index in this.threads) {
          if (this.threads[index].thread.pid === res.threadId) {
            const images = [];
            if (res.images.data) {
              res.images.data.forEach(image => {
                images.push(this.$store.getters['jv/get'](`attachments/${image.id}`));
              });
            }
            this.threads[index].attachment = images;
            this.$forceUpdate();
            break;
          }
        }
      });

      // 详情页编辑增加图片时首页增加图片
      // 这是接收的商品
      this.$u.event.$on('refreshGoods', res => {
        // eslint-disable-next-line no-restricted-syntax
        for (const index in this.threads) {
          if (this.threads[index].thread.pid === res.threadId) {
            this.threads[index].thread.postGoods = res.goods;
            this.$forceUpdate();
            break;
          }
        }
      });

      // 详情页编辑定位
      this.$u.event.$on('updateLocation', (id, res) => {
        this.threads.forEach((item, index) => {
          if (item.thread.pid === id) {
            this.threads[index].latitude = res.latitude || '';
            this.threads[index].location = res.location || '';
            this.threads[index].longitude = res.longitude || '';
            this.threads[index].address = res.address || '';
          }
        });
      });
    },
    computed: {
      redCircle() {
        return this.user.unreadNotifications;
      },
    },
    methods: {
      admin() {
        this.tabs.push('审核');
      },
      InputSearch(keyword) {
        this.keyword = keyword;
        this.pageNum = 1;
        this.isResetList = true;
        this.loadThreads();
      },
      scrpllsip(e, index) {
        this.scrollnumber = e;
        this.scrollindex = index;
        this.switchscroll = true;
        this.scrollTop = this.rollingHeight;
      },
      TabClick(e) {
        let self = this;
        this.current = e.currentIndex;
        this.pageNum = 1;
        this.isResetList = true;
        this.threads = [];
        this.preThreadsData = [];
        if (this.current == 2) {
          uni.getLocation({
            type: 'gcj02',
            success: function(res) {
              self.location = {
                longitude: res.longitude,
                latitude: res.latitude
              };

              self.loadThreads()
            }
          });
          // } else if (this.current == 3) {
          //  //  let params = {
          //  //  'filter[type]': '2',
          //  //  'filter[approved]': 1,
          //  //  'page': 1,
          //  //  'perPage': 10,

          //  //  };
          //  //  console.log('params',params)
          //  // this.$store.dispatch('jv/get', ['threads.v2', { params }])
          //  //  // this.$store
          //  //  //   .dispatch('jv/get', params)
          //  //    .then(data => {
          //  //  	  console.log(data)
          //  //    });

          //   uni.navigateTo({
          //     url: `/mainpage/bbs/video?thread_id=${ this.searchIds}`,
          //   });
        } else {
          this.loadThreads()
        }

      },
      async LoadTopThreads() {
        let searchidNum = '';
        if (this.searchIds || this.searchIds === 0) {
          if (!(this.searchIds instanceof Array)) {
            searchidNum = [this.searchIds];
          } else {
            searchidNum = this.searchIds;
          }
        } else {
          searchidNum = [];
        }
        const sun = {
          page: 1,
          perPage: 1,
          filter: {
            sticky: 1,
            approved: 1,
          },
        };
        if (searchidNum.length > 0 && this.searchIds !== -1 && this.searchIds !== 0) {
          sun.filter.categoryids = searchidNum;
        }
        let res = await apiRequest.readThreadList({
          params: sun
        });
        this.threads_top = res.Data.pageData;
      },
      // 首页内容部分数据请求
      async loadThreads() {
        // console.log('loadThreads')
        let searchidNum = '';
        if (this.searchIds || this.searchIds === 0) {
          if (!(this.searchIds instanceof Array)) {
            searchidNum = [this.searchIds];
          } else {
            searchidNum = this.searchIds;
          }
        } else {
          searchidNum = [];
        }

        const sun = {
          _jv: {
            type: 'threads',
          },
          page: this.pageNum,
          perPage: 10,
          filter: {
            approved: 1,
            types: [0, 1, 3, 5, 6],
            sticky: 0,
            keyword: this.keyword,
          },
        };

        switch (this.current) {

          case 1:
            //精华
            sun.filter = {
              types: [0, 1, 3, 5, 6],
              essence: 1,
              approved: 1,
            }
            break;
          case 2:
            // 附近
            sun.filter = {
              location: this.location.longitude + ',' + this.location.latitude + ',' + 10,
              approved: 1,
              sort: 2,
              sticky: 0,
            }
            break;
          case 3:
            // 视频
            sun.filter = {
              types: [2],
              approved: 1,
              sticky: 0,
              sort: 2,
            }
            break;
          case 4:
            // 审核
            sun.filter = {
              approved: 0,
            }
            break;
        }

        if (searchidNum.length > 0 && this.searchIds !== -1 && this.searchIds !== 0) {
          sun.filter.categoryids = searchidNum;
        }
        if (this.searchIds === 0) {
          sun.homeSequence = 1;
        }
        if (this.threadType || this.threadType === 0) {
          sun.filter.types = [this.threadType];
        }

        let res;
        try {
          if (this.preThreadsData && this.preThreadsData[this.pageNum]) {
            res = this.preThreadsData[this.pageNum];
            this.preThreadsData = null;

          } else {
            // 这是清空，是处理快速滚动特殊情况下，
            // preThreadsData有数据，但是页数不匹配的情况
            this.preThreadsData = null;
            res = await apiRequest.readThreadList({
              params: sun
            });
          }
          if (res.Data) {

            this.loadingType = res.Data.currentPage < res.Data.totalPage ? 'more' : 'nomore';
          }

          if (this.isResetList) {
            this.threads = res.Data.pageData;
          } else {
            this.threads = [...this.threads, ...res.Data.pageData];
          }
          this.isResetList = false;


        } catch (err) {
          console.log(err);
        }

      },
      getQueryString(name) {
        const reg = new RegExp(`(^|&)${name}([^&]*)(&|$)`);
        const r = window.location.search.substr(1).match(reg);
        if (r != null) return r[2].substring(1);
        return null;
      },
      handleGroup(data) {
        // 新接口回答的用户组是对象。
        let groups = [data];
        if (groups.length > 0) {
          groups = groups.filter(item => item && item.isDisplay);
        }
        return groups[0] ? [groups[0]] : [];
      },
      // 内容部分点击跳转到详情页
      // eslint-disable-next-line
      contentClick: throttle(function(thread) {
        console.log('contentClick')
        if (thread.thread.canViewPost) {
          uni.navigateTo({
            url: `/topic/index?id=${thread.thread.pid}`,
          });
        } else {
          this.$refs.toast.show({
            message: this.i18n.t('home.noPostingTopic')
          });
        }
      }, 1000),
      // contentClick: throttle(function(thread) {
      //   console.log('contentClick')
      //   if (thread.thread.canViewPost) {
      //     if (this.current == 3) {

      //       uni.navigateTo({
      //         url: `/mainpage/bbs/videoplay?id=${thread.thread.pid}`,
      //       });
      //     } else {
      //       uni.navigateTo({
      //         url: `/topic/index?id=${thread.thread.pid}`,
      //       });
      //     }
      //   } else {
      //     this.$refs.toast.show({
      //       message: this.i18n.t('home.noPostingTopic')
      //     });
      //   }
      // }, 1000),
      search(val) {

      },
      onClickItem() {

      },
      // 内容部分点赞按钮点击事件
      handleIsGreat(id, canLike, isLiked, likedCount, thread) {

        const jvObj = {
          type: 'posts',
          id,
        };
        let params = {
          _jv: jvObj,
          isLiked: !isLiked,
        };
        this.$store
          .dispatch('jv/patch', params)
          .then(data => {});
      },

      // 筛选分类里的搜索
      searchClick() {
        uni.navigateTo({
          url: '/pages/site/search',
        });
        this.show = false;
      },
      // 点击置顶跳转到详情页
      // eslint-disable-next-line
      stickyClick: throttle(function(id) {
          if (this.current == 3) {
            uni.navigateTo({
              url: `/mainpage/bbs/videoplay?id=${id}`,
            });
          } else {
            uni.navigateTo({
              url: `/topic/index?id=${id}`,
            });
          }
        },
        1000),
      // 内容部分点击评论跳到详情页
      // eslint-disable-next-line
      commentClick: throttle(function(id) {
        if (this.current == 3) {
          uni.navigateTo({
            url: `/mainpage/bbs/videoplay?id=${id}`,
          });
        } else {
          uni.navigateTo({
            url: `/topic/index?id=${id}`,
          });
        }
      }, 1000),
      // 内容部分点击跳转到详情页
      // eslint-disable-next-line
      // contentClick: throttle(function(thread) {
      //   if (thread.thread.canViewPost) {
      //     if (this.current == 3) {
      //       uni.navigateTo({
      //         url: `/mainpage/bbs/videoplay?id=${thread.thread.pid}`,
      //       });
      //     } else {
      //       uni.navigateTo({
      //         url: `/topic/index?id=${thread.thread.pid}`,
      //       });
      //     }
      //   } else {
      //     this.$refs.toast.show({
      //       message: this.i18n.t('home.noPostingTopic')
      //     });
      //   }
      // }, 1000),
      // 点击头像调转到个人主页
      headClick(id) {
        if (!id || id <= 0) {
          return;
        }
        uni.navigateTo({
          url: `/pages/profile/index?userId=${id}`,
        });
      },
      // 点击用户名跳转个人主页
      answeClick(id) {
        if (id <= 0) {
          return;
        }
        uni.navigateTo({
          url: `/pages/profile/index?userId=${id}`,
        });
      },
      // 点击被提问者用户名
      beAskClick(id) {
        if (id <= 0) {
          return;
        }
        uni.navigateTo({
          url: `/pages/profile/index?userId=${id}`,
        });
      },
      // 点击已回答用户的头像调转到个人主页
      headAnswerClick(id) {
        if (id <= 0) {
          return;
        }
        uni.navigateTo({
          url: `/pages/profile/index?userId=${id}`,
        });
      },
      /* 获取数据 */
      getData(page_id) {
        const self = this;
        self._get(
          'index/index', {
            page_id: page_id,
          },
          function(res) {
            self.background = res.data.background;
            self.title_name = res.data.page.params.title;
            self.bgcolor = res.data.page.style.titleBackgroundColor;
            self.msgNum = res.data.msgNum;
            self.toplogo = res.data.page.style.toplogo;

            self.page_info = res.data.page;
            self.items = res.data.items;
            self.setPage(self.page_info);
          },
        );
      },

      /* 设置页面 */
      setPage(page) {
        uni.setNavigationBarTitle({
          title: page.params.name,
        });

        let colors = '#000000';
        if (page.style.titleTextColor == 'white') {
          // 字母要小 写
          colors = '#ffffff';
        }
        uni.setNavigationBarColor({
          frontColor: colors,
          backgroundColor: page.style.titleBackgroundColor,
        });
      },
      OpenPublish() {
        this.$refs.footer.OpenPublish();
      },
      handleVideoPlay() {

      },
      scrollsetup() {

      },
      fullscreenchange() {

      }
    }
  }
</script>

<style>
  .header_box {

    /* #ifdef MP-WEIXIN */
    width: 500rpx;
    /* #endif */
  }

  .head_top {
    background-color: rgb(75, 206, 215);
  }

  .head_icon {
    display: flex;
    flex-direction: column;
    margin-top: 50rpx;
    font-size: 25rpx;
    color: #FFF;
    /* #ifdef MP-WEIXIN || APP-PLUS */
    margin-top: 80rpx;
    /* #endif */
  }

  .head_back {
    padding-left: 10rpx;
  }

  .content {
    display: flex;
    flex-direction: row;
    column-count: 2;
    flex-wrap: wrap;
    align-content: center;
    column-gap: 0;
    justify-content: space-between;

  }
  .message {
    position: relative;
  }

  .message:after {
    position: absolute;
    top: -2px;
    right: 8px;
    width: 7px;
    height: 7px;
    background:#F00808;
    border-radius: 50%;
    content: '';
  }
</style>
